home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / architecture / byte_order.h < prev    next >
Text File  |  1993-03-15  |  7KB  |  497 lines

  1. /*
  2.  * Copyright (c) 1992 NeXT Computer, Inc.
  3.  *
  4.  * Byte ordering conversion.
  5.  *
  6.  * HISTORY
  7.  *
  8.  * 20 October 1992 David E. Bohman at NeXT
  9.  *    Added #ifdef wrapper to prevent multiple inclusions of this file.
  10.  *
  11.  * 8 October 1992 David E. Bohman at NeXT
  12.  *    Converted to NXxxx versions.  Condensed history.
  13.  *
  14.  * 18 May 1992 David E. Bohman at NeXT
  15.  *    Created.
  16.  */
  17.  
  18. #ifndef    _ARCHITECTURE_BYTE_ORDER_H_
  19. #define _ARCHITECTURE_BYTE_ORDER_H_
  20.  
  21. typedef unsigned long NXSwappedFloat;
  22. typedef unsigned long long NXSwappedDouble;
  23.  
  24. #import <architecture/ARCH_INCLUDE.h>
  25.  
  26. #import ARCH_INCLUDE(architecture/, byte_order.h)
  27.  
  28. /*
  29.  * Identify the byte order
  30.  * of the current host.
  31.  */
  32.  
  33. enum NXByteOrder {
  34.     NX_UnknownByteOrder,
  35.     NX_LittleEndian,
  36.     NX_BigEndian
  37. };
  38.  
  39. static __inline__
  40. enum NXByteOrder
  41. NXHostByteOrder(void)
  42. {
  43.     unsigned int    _x;
  44.     
  45.     _x = (NX_BigEndian << 24) | NX_LittleEndian;
  46.         
  47.     return ((enum NXByteOrder)*((unsigned char *)&_x));
  48. }
  49.  
  50. /*
  51.  * The predicated versions
  52.  * are defined here in terms
  53.  * of the unpredicated ones.
  54.  */
  55.  
  56. #if    __BIG_ENDIAN__
  57.  
  58. static __inline__
  59. unsigned short
  60. NXSwapBigShortToHost(
  61.     unsigned short    x
  62. )
  63. {
  64.     return (x);
  65. }
  66.  
  67. static __inline__
  68. unsigned int
  69. NXSwapBigIntToHost(
  70.     unsigned int    x
  71. )
  72. {
  73.     return (x);
  74. }
  75.  
  76. static __inline__
  77. unsigned long
  78. NXSwapBigLongToHost(
  79.     unsigned long    x
  80. )
  81. {
  82.     return (x);
  83. }
  84.  
  85. static __inline__
  86. unsigned long long
  87. NXSwapBigLongLongToHost(
  88.     unsigned long long    x
  89. )
  90. {
  91.     return (x);
  92. }
  93.  
  94. static __inline__
  95. double
  96. NXSwapBigDoubleToHost(
  97.     NXSwappedDouble    x
  98. )
  99. {
  100.     return NXConvertSwappedDoubleToHost(x);
  101. }
  102.  
  103. static __inline__
  104. float
  105. NXSwapBigFloatToHost(
  106.     NXSwappedFloat    x
  107. )
  108. {
  109.     return NXConvertSwappedFloatToHost(x);
  110. }
  111.  
  112. static __inline__
  113. unsigned short
  114. NXSwapHostShortToBig(
  115.     unsigned short    x
  116. )
  117. {
  118.     return (x);
  119. }
  120.  
  121. static __inline__
  122. unsigned int
  123. NXSwapHostIntToBig(
  124.     unsigned int    x
  125. )
  126. {
  127.     return (x);
  128. }
  129.  
  130. static __inline__
  131. unsigned long
  132. NXSwapHostLongToBig(
  133.     unsigned long    x
  134. )
  135. {
  136.     return (x);
  137. }
  138.  
  139. static __inline__
  140. unsigned long long
  141. NXSwapHostLongLongToBig(
  142.     unsigned long long    x
  143. )
  144. {
  145.     return (x);
  146. }
  147.  
  148. static __inline__
  149. NXSwappedDouble
  150. NXSwapHostDoubleToBig(
  151.     double        x
  152. )
  153. {
  154.     return NXConvertHostDoubleToSwapped(x);
  155. }
  156.  
  157. static __inline__
  158. NXSwappedFloat
  159. NXSwapHostFloatToBig(
  160.     float        x
  161. )
  162. {
  163.     return NXConvertHostFloatToSwapped(x);
  164. }
  165.  
  166. static __inline__
  167. unsigned short
  168. NXSwapLittleShortToHost(
  169.     unsigned short    x
  170. )
  171. {
  172.     return (NXSwapShort(x));
  173. }
  174.  
  175. static __inline__
  176. unsigned int
  177. NXSwapLittleIntToHost(
  178.     unsigned int    x
  179. )
  180. {
  181.     return (NXSwapInt(x));
  182. }
  183.  
  184. static __inline__
  185. unsigned long
  186. NXSwapLittleLongToHost(
  187.     unsigned long    x
  188. )
  189. {
  190.     return (NXSwapLong(x));
  191. }
  192.  
  193. static __inline__
  194. unsigned long long
  195. NXSwapLittleLongLongToHost(
  196.     unsigned long long    x
  197. )
  198. {
  199.     return (NXSwapLongLong(x));
  200. }
  201.  
  202. static __inline__
  203. double
  204. NXSwapLittleDoubleToHost(
  205.     NXSwappedDouble    x
  206. )
  207. {
  208.     return NXConvertSwappedDoubleToHost(NXSwapDouble(x));
  209. }
  210.  
  211. static __inline__
  212. float
  213. NXSwapLittleFloatToHost(
  214.     NXSwappedFloat    x
  215. )
  216. {
  217.     return NXConvertSwappedFloatToHost(NXSwapFloat(x));
  218. }
  219.  
  220. static __inline__
  221. unsigned short
  222. NXSwapHostShortToLittle(
  223.     unsigned short    x
  224. )
  225. {
  226.     return (NXSwapShort(x));
  227. }
  228.  
  229. static __inline__
  230. unsigned int
  231. NXSwapHostIntToLittle(
  232.     unsigned int    x
  233. )
  234. {
  235.     return (NXSwapInt(x));
  236. }
  237.  
  238. static __inline__
  239. unsigned long
  240. NXSwapHostLongToLittle(
  241.     unsigned long    x
  242. )
  243. {
  244.     return (NXSwapLong(x));
  245. }
  246.  
  247. static __inline__
  248. unsigned long long
  249. NXSwapHostLongLongToLittle(
  250.     unsigned long long    x
  251. )
  252. {
  253.     return (NXSwapLongLong(x));
  254. }
  255.  
  256. static __inline__
  257. NXSwappedDouble
  258. NXSwapHostDoubleToLittle(
  259.     double        x
  260. )
  261. {
  262.     return NXSwapDouble(NXConvertHostDoubleToSwapped(x));
  263. }
  264.  
  265. static __inline__
  266. NXSwappedFloat
  267. NXSwapHostFloatToLittle(
  268.     float        x
  269. )
  270. {
  271.     return NXSwapFloat(NXConvertHostFloatToSwapped(x));
  272. }
  273.  
  274. #endif
  275.  
  276. #if    __LITTLE_ENDIAN__
  277.  
  278. static __inline__
  279. unsigned short
  280. NXSwapBigShortToHost(
  281.     unsigned short    x
  282. )
  283. {
  284.     return (NXSwapShort(x));
  285. }
  286.  
  287. static __inline__
  288. unsigned int
  289. NXSwapBigIntToHost(
  290.     unsigned int    x
  291. )
  292. {
  293.     return (NXSwapInt(x));
  294. }
  295.  
  296. static __inline__
  297. unsigned long
  298. NXSwapBigLongToHost(
  299.     unsigned long    x
  300. )
  301. {
  302.     return (NXSwapLong(x));
  303. }
  304.  
  305. static __inline__
  306. unsigned long long
  307. NXSwapBigLongLongToHost(
  308.     unsigned long long    x
  309. )
  310. {
  311.     return (NXSwapLongLong(x));
  312. }
  313.  
  314. static __inline__
  315. double
  316. NXSwapBigDoubleToHost(
  317.     NXSwappedDouble    x
  318. )
  319. {
  320.     return NXConvertSwappedDoubleToHost(NXSwapDouble(x));
  321. }
  322.  
  323. static __inline__
  324. float
  325. NXSwapBigFloatToHost(
  326.     NXSwappedFloat    x
  327. )
  328. {
  329.     return NXConvertSwappedFloatToHost(NXSwapFloat(x));
  330. }
  331.  
  332. static __inline__
  333. unsigned short
  334. NXSwapHostShortToBig(
  335.     unsigned short    x
  336. )
  337. {
  338.     return (NXSwapShort(x));
  339. }
  340.  
  341. static __inline__
  342. unsigned int
  343. NXSwapHostIntToBig(
  344.     unsigned int    x
  345. )
  346. {
  347.     return (NXSwapInt(x));
  348. }
  349.  
  350. static __inline__
  351. unsigned long
  352. NXSwapHostLongToBig(
  353.     unsigned long    x
  354. )
  355. {
  356.     return (NXSwapLong(x));
  357. }
  358.  
  359. static __inline__
  360. unsigned long long
  361. NXSwapHostLongLongToBig(
  362.     unsigned long long    x
  363. )
  364. {
  365.     return (NXSwapLongLong(x));
  366. }
  367.  
  368. static __inline__
  369. NXSwappedDouble
  370. NXSwapHostDoubleToBig(
  371.     double        x
  372. )
  373. {
  374.     return (NXSwapDouble(NXConvertHostDoubleToSwapped(x)));
  375. }
  376.  
  377. static __inline__
  378. NXSwappedFloat
  379. NXSwapHostFloatToBig(
  380.     float        x
  381. )
  382. {
  383.     return (NXSwapFloat(NXConvertHostFloatToSwapped(x)));
  384. }
  385.  
  386. static __inline__
  387. unsigned short
  388. NXSwapLittleShortToHost(
  389.     unsigned short    x
  390. )
  391. {
  392.     return (x);
  393. }
  394.  
  395. static __inline__
  396. unsigned int
  397. NXSwapLittleIntToHost(
  398.     unsigned int    x
  399. )
  400. {
  401.     return (x);
  402. }
  403.  
  404. static __inline__
  405. unsigned long
  406. NXSwapLittleLongToHost(
  407.     unsigned long    x
  408. )
  409. {
  410.     return (x);
  411. }
  412.  
  413. static __inline__
  414. unsigned long long
  415. NXSwapLittleLongLongToHost(
  416.     unsigned long long    x
  417. )
  418. {
  419.     return (x);
  420. }
  421.  
  422. static __inline__
  423. double
  424. NXSwapLittleDoubleToHost(
  425.     NXSwappedDouble    x
  426. )
  427. {
  428.     return NXConvertSwappedDoubleToHost(x);
  429. }
  430.  
  431. static __inline__
  432. float
  433. NXSwapLittleFloatToHost(
  434.     NXSwappedFloat    x
  435. )
  436. {
  437.     return NXConvertSwappedFloatToHost(x);
  438. }
  439.  
  440. static __inline__
  441. unsigned short
  442. NXSwapHostShortToLittle(
  443.     unsigned short    x
  444. )
  445. {
  446.     return (x);
  447. }
  448.  
  449. static __inline__
  450. unsigned int
  451. NXSwapHostIntToLittle(
  452.     unsigned int    x
  453. )
  454. {
  455.     return (x);
  456. }
  457.  
  458. static __inline__
  459. unsigned long
  460. NXSwapHostLongToLittle(
  461.     unsigned long    x
  462. )
  463. {
  464.     return (x);
  465. }
  466.  
  467. static __inline__
  468. unsigned long long
  469. NXSwapHostLongLongToLittle(
  470.     unsigned long long    x
  471. )
  472. {
  473.     return (x);
  474. }
  475.  
  476. static __inline__
  477. NXSwappedDouble
  478. NXSwapHostDoubleToLittle(
  479.     double        x
  480. )
  481. {
  482.     return NXConvertHostDoubleToSwapped(x);
  483. }
  484.  
  485. static __inline__
  486. NXSwappedFloat
  487. NXSwapHostFloatToLittle(
  488.     float        x
  489. )
  490. {
  491.     return NXConvertHostFloatToSwapped(x);
  492. }
  493.  
  494. #endif
  495.  
  496. #endif    _ARCHITECTURE_BYTE_ORDER_H_
  497.